package com.yxe.controller;


import com.yxe.api.CommonResult;
import com.yxe.pojo.House;
import com.yxe.service.HouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2022-12-10
 */
@RestController
@RequestMapping("house")
@Slf4j
@Api(tags = "房源")
public class HouseController {

    @Autowired
    private HouseService houseService;

    // 查询所有房源信息
    @GetMapping("findAll")
    @ApiOperation("所有房源")
    @ResponseBody
    public CommonResult findAll() {
        List<House> houseList = houseService.findAll();

        return CommonResult.success(houseList,"查询全部");
    }

    // 根据一个或多个关键词查询房源信息
    @GetMapping("findHouse")
    @ApiOperation("筛选查询")
    @ResponseBody
    public CommonResult findHouse(House house){

        List<House> houseList = houseService.findHouse(house);

        return CommonResult.success(houseList);
    }

    // 根据房源名称模糊查询房源信息
    @GetMapping("findHouseByName")
    @ApiOperation("模糊查询")
    @ResponseBody
    public CommonResult findHouseByName(String name){

        List<House> houseList = houseService.findHouseByName(name);

        return CommonResult.success(houseList,"模糊查询");
    }
}